package com.zq.assistant.func.ioc.finder.field;

import com.zq.assistant.func.ioc.finder.cache.FindCache;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.List;

/**
 * Created by zhangqiang on 17-7-11.
 */

public class CachedFieldFinder extends BaseFieldFinder {

    private FindCache<Class,List<Field>> findCache;

    public CachedFieldFinder(Class<?> abortClass, FindCache<Class,List<Field>> findCache) {
        super(abortClass);
        this.findCache = findCache;
    }


    @Override
    public List<Field> findInjectFields(Class targetClass, Class<? extends Annotation> annotationClass) {

        if(findCache != null){

            List<Field> fieldList = findCache.get(targetClass);
            if(fieldList != null){
                return fieldList;
            }
        }

        List<Field> fieldList = super.findInjectFields(targetClass, annotationClass);
        if(fieldList != null && findCache != null){

            findCache.put(targetClass,fieldList);
        }
        return fieldList;
    }
}
